from django.db import models


# Create your models here.

class District(models.Model):
    """
    地区
    """
    # 数据id
    _id = models.AutoField(primary_key=True)
    # 地区ID
    district_id = models.IntegerField(verbose_name='地区编号', null=True, default=None)
    # 父级行政区域（省级行政区域的父级为None）
    parent = models.ForeignKey(to='self', on_delete=models.DO_NOTHING, db_column='pid', null=True)
    # 地区名称
    name = models.CharField(max_length=50)

    # 地区等级
    district_level = models.IntegerField(choices=(
        (0, '省/自治区/直辖市'),
        (1, '地级市/地区/自治州/盟'),
        (2, '县级市、县'),
        (3, '乡镇/街道'),
        (4, '村庄/居委会'),
    ))
    # 城乡分类码
    village_code = models.IntegerField(choices=(
        (111, "主城区"),
        (112, "城乡结合区"),
        (121, "镇中心区"),
        (122, "镇乡结合区"),
        (123, "特殊区域"),
        (210, "乡中心区"),
        (220, "村庄"),
    ), null=True, default=None)

    class Meta:
        managed = False
        db_table = 'tb_district'


class House(models.Model):
    # 数据id
    _id = models.AutoField(primary_key=True)
    # # 地区外键 等级必须是小区
    district = models.ForeignKey(to=District, on_delete=models.DO_NOTHING,
                                 limit_choices_to={'district_level': 4})
    # 房源标题
    title = models.CharField(max_length=50)
    # 房源面积
    area = models.IntegerField()
    # # 房源楼层
    # floor = models.IntegerField()
    # # 房源总楼层
    # totalfloor = models.IntegerField()
    # # 房源朝向
    # direction = models.CharField(max_length=10)
    # # 房源价格
    # price = models.IntegerField()
    # # 房源价格单位
    # priceunit = models.CharField(max_length=10)
    # # 房源详情
    # detail = models.CharField(max_length=511, default='')
    # # 房源图片（主图）
    # mainphoto = models.CharField(max_length=255)
    # # 房源发布日期
    # pubdate = models.DateField(auto_now_add=True)
    # # 房源所在街道
    # street = models.CharField(max_length=255)
    # # 是否有地铁
    # hassubway = models.BooleanField(default=False)
    # # 是否支持合租
    # isshared = models.BooleanField(default=False)
    #
    # # 房源说明
    # document = models.CharField(max_length=255, default='')
